<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="机构类型" prop="orgType">
        <el-select class="w-40" v-model="queryParams.orgType" placeholder="请输入机构类型" clearable>
          <el-option v-for="dict in organizationType" :key="dict.value" :label="dict.label"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="机构层级" prop="level">
        <el-select class="w-40" v-model="queryParams.level" placeholder="请输入机构层级" clearable>
          <el-option v-for="dict in organizationLevel" :key="dict.value" :label="`${dict.label}`"
            :value="dict.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="机构名称" prop="orgName">
        <el-input v-model="queryParams.orgName" placeholder="请输入机构名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="省" prop="province">
        <el-input v-model="queryParams.province" placeholder="请输入省名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="市" prop="city">
        <el-input v-model="queryParams.city" placeholder="请输入区名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="区" prop="district">
        <el-input v-model="queryParams.district" placeholder="请输入区名称" clearable @keyup.enter="handleQuery" />
      </el-form-item>

<!--      <el-form-item label="企业所属地" label-width="100px" prop="provinceName">
        <CityChoose class="!w-100" v-model:provinceSiteId="queryParams.provinceSiteId"
          v-model:citySiteId="queryParams.citySiteId" v-model:areaSiteId="queryParams.areaSiteId" />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['manage:organization:add']">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate"
          v-hasPermi="['manage:organization:edit']">修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['manage:organization:remove']">删除
        </el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport"
          v-hasPermi="['manage:organization:export']">导出
        </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-tabs v-model="activeTab" @tab-change="handleTabChange" class="mb8">
      <el-tab-pane label="全部" name=""></el-tab-pane>
      <el-tab-pane v-for="tab in auditStatus" :key="tab.value" :label="tab.label" :name="tab.value" />

    </el-tabs>
    <el-table v-loading="loading" border :data="organizationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="ID" align="center" prop="id"/>
<!--      <el-table-column label="上级ID" align="center" prop="parentId" show-overflow-tooltip />-->
      <el-table-column label="机构类型" align="center" prop="orgType" width="120">
        <template #default="scope">
          <dict-tag :options="organizationType" :value="scope.row.orgType" />
        </template>
      </el-table-column>
      <el-table-column label="机构层级" width="100" align="center" prop="level">
        <template #default="scope">
          <dict-tag :options="organizationLevel" :value="scope.row.level" />
        </template>
      </el-table-column>
      <el-table-column label="机构编码" align="center" prop="orgCode" width="170" />
      <el-table-column label="机构路径" align="center" prop="orgPath" show-overflow-tooltip width="120" />
      <el-table-column label="机构名称" align="center" prop="orgName" show-overflow-tooltip width="120" />
      <el-table-column label="连接地址" align="center" prop="orgUrl" show-overflow-tooltip />
      <el-table-column label="机构简称" align="center" prop="shortName" width="180" />
      <el-table-column label="机构logo" align="center" prop="logo" show-overflow-tooltip width="120" />
      <el-table-column label="推荐logo" align="center" prop="recommendLogo" show-overflow-tooltip width="120" />
      <el-table-column label="简介" align="center" prop="introduction" show-overflow-tooltip width="120" />
      <el-table-column label="服务区域" align="center" prop="national" show-overflow-tooltip>
        <template #default="scope">
          <dict-tag :options="national_type" :value="scope.row.national" />
        </template>
      </el-table-column>
      <el-table-column label="服务区域编码" align="center" prop="nationalCode" show-overflow-tooltip width="130" />
      <el-table-column label="省" align="center" prop="province" />
      <el-table-column label="市" align="center" prop="city" />
      <el-table-column label="区" align="center" prop="district" width="150" />
      <el-table-column label="详细地址" align="center" prop="address" show-overflow-tooltip width="150" />
      <el-table-column label="推荐" align="center" prop="recommend">
        <template #default="scope">
          <dict-tag :options="yesOrNo" :value="scope.row.recommend" />
        </template>
      </el-table-column>
      <el-table-column label="置顶" align="center" prop="top">
        <template #default="scope">
          <dict-tag :options="yesOrNo" :value="scope.row.top" />
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :options="status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" prop="sort" />
      <el-table-column label="产品总数" align="center" prop="productTotal" />
      <el-table-column label="对接总数" align="center" prop="dockingTotal" />
      <el-table-column label="删除" align="center" prop="deleted">
        <template #default="scope">
          <dict-tag :options="yesOrNo" :value="scope.row.deleted" />
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip />
      <el-table-column label="白名单机构" align="center" prop="whitelistMarker" width="100" />
      <el-table-column label="融资流程" align="center" prop="financingProcess" show-overflow-tooltip width="120">
        <template #default="scope">
          <dict-tag :options="financing_process_type" :value="scope.row.financingProcess" />
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" width="120" show-overflow-tooltip>
        <template #default="scope">
          <dict-tag :options="auditStatus" :value="scope.row.audit" />
        </template>
      </el-table-column>
      <el-table-column label="拒绝原因" align="center" width="150" show-overflow-tooltip>
        <template #default="scope">
          {{ scope.row.auditDesc }}
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" width="180">
        <template #default="scope">
          <span v-if="scope.row.auditTime">
            {{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed='right' width="110">
        <template #default="scope">
          <el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)" v-hasPermi="['manage:organization:add']">添加分支
          </el-button>
          <el-button link type="primary" icon="User" @click="handleToUsers(scope.row)"
            v-hasPermi="['manage:organization:edit']">
            人员
          </el-button>
          <el-button v-if="scope.row.audit === '0'" link type="primary" icon="Edit" @click="handleCheck(scope.row)"
            v-hasPermi="['manage:organization:edit']">审核
          </el-button>
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['manage:organization:edit']">修改
          </el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
            v-hasPermi="['manage:organization:remove']">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改金融机构信息对话框 -->
    <el-dialog :title="title" v-model="open" width="1200px" append-to-body>
      <el-form ref="organizationRef" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="30">
          <el-col :span="12">
<!--            <el-form-item label="上级" prop="orgCode">
              <el-input v-model="form.parentId" placeholder="请输入上级ID" />
            </el-form-item>-->
            <el-form-item label="上级机构" prop="parentOrgName">
              <el-input v-model="form.parentOrgName" disabled placeholder="上级机构名称" />
              <!-- 隐藏的 parentId 用于提交 -->
              <el-input v-model="form.parentId" type="hidden" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="机构类型" prop="orgType">
              <el-select v-model="form.orgType" placeholder="请输入机构类型">
                <el-option v-for="dict in organizationType" :key="dict.value" :label="dict.label"
                  :value="Number(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="机构层级" prop="level">
              <el-select v-model="form.level" placeholder="请输入机构层级" disabled>
                <el-option v-for="dict in organizationLevel" :key="dict.value" :label="dict.label"
                  :value="Number(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="机构编码" prop="orgCode">
              <el-input v-model="form.orgCode" placeholder="请输入机构编码" />
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span="12">
            <el-form-item label="机构路径" prop="orgPath">
              <el-input v-model="form.orgPath" placeholder="请输入机构路径" />
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="机构名称" prop="orgName">
              <el-input v-model="form.orgName" placeholder="请输入机构名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="连接地址" prop="orgUrl">
              <el-input v-model="form.orgUrl" placeholder="请输入连接地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="机构简称" prop="shortName">
              <el-input v-model="form.shortName" placeholder="请输入机构简称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="机构logo" prop="logo">
              <el-input v-model="form.logo" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="推荐logo" prop="recommendLogo">
              <el-input v-model="form.recommendLogo" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="简介" prop="introduction">
              <el-input v-model="form.introduction" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="服务区域" prop="national">
              <el-select v-model="form.national" placeholder="请选择服务区域">
                <el-option v-for="dict in national_type" :key="dict.value" :label="dict.label"
                  :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="服务区域" prop="nationalCode">
              <el-input v-model="form.national" placeholder="请输入服务区域编码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="省" prop="province">
              <el-input v-model="form.province" placeholder="请输入省" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="市" prop="city">
              <el-input v-model="form.city" placeholder="请输入市" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区县" prop="district">
              <el-input v-model="form.district" placeholder="请输入区县" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="省代码" prop="provinceCode">
              <el-input v-model="form.provinceCode" placeholder="请输入省代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="市代码" prop="cityCode">
              <el-input v-model="form.cityCode" placeholder="请输入市代码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区" prop="districtCode">
              <el-input v-model="form.districtCode" placeholder="请输入区" />
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="详细地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入详细地址" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="推荐" prop="recommend">
              <el-radio-group v-model="form.recommend">
                <el-radio v-for="dict in yesOrNo" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="置顶" prop="top">
              <el-radio-group v-model="form.top">
                <el-radio v-for="dict in yesOrNo" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio v-for="dict in status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序" prop="sort">
              <el-input v-model="form.sort" placeholder="请输入排序" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品总数" prop="productTotal">
              <el-input v-model="form.productTotal" placeholder="请输入产品总数" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="对接总数" prop="dockingTotal">
              <el-input v-model="form.dockingTotal" placeholder="请输入对接总数" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="删除" prop="deleted">
              <el-radio-group v-model="form.deleted">
                <el-radio v-for="dict in yesOrNo" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="白名单" prop="whitelistMarker">
              <el-input v-model="form.whitelistMarker" placeholder="请输入白名单机构" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="融资流程" prop="financingProcess">
              <el-select v-model="form.financingProcess" placeholder="请选择融资流程">
                <el-option v-for="dict in financing_process_type" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog :title="title" v-model="checkOpen" width="500px" append-to-body>
      <el-form ref="checkRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="审核结果" prop="audit">
          <el-select v-model="form.audit" placeholder="请选择审核结果">
            <el-option v-for="dict in auditStatus" :key="dict.value" :label="dict.label"
              :value="dict.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核描述" prop="auditDesc">
          <el-input v-model="form.auditDesc" placeholder="请输入描述" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitCheckForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Organization">

import CityChoose from '@/components/CityChoose/index.vue'
import {
  listOrganization,
  getOrganization,
  delOrganization,
  addOrganization,
  updateOrganization,
  check
} from "@/api/manage/organization"

const router = useRouter()
const { proxy } = getCurrentInstance()
const {
  national_type,
  yesOrNo,
  status,
  financing_process_type,
  organizationLevel,
  organizationType,
  auditStatus
} = proxy.useDict('national_type', 'yesOrNo', 'status', 'financing_process_type', 'organizationLevel', 'organizationType', 'auditStatus')

const organizationList = ref([])
const bizOrganizationAuditList = ref([])
const open = ref(false)
const checkOpen = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const checkedBizOrganizationAudit = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const activeTab = ref("0")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    orgType: null,
    level: null,
    orgName: null,
    province: null,
    city: null,
    district: null,
    status: null,
    audit: null,
  },
  rules: {
    parentId: [
      { required: true, message: "上级ID不能为空", trigger: "blur" }
    ],
    orgType: [
      { required: true, message: "机构类型不能为空", trigger: "blur" }
    ],
    level: [
      { required: true, message: "机构层级不能为空", trigger: "blur" }
    ],
    orgName: [
      { required: true, message: "机构名称不能为空", trigger: "blur" }
    ],
    shortName: [
      { required: true, message: "机构简称不能为空", trigger: "blur" }
    ],
    logo: [
      { required: true, message: "机构logo不能为空", trigger: "blur" }
    ],
    national: [
      { required: true, message: "服务区域不能为空", trigger: "change" }
    ],
    province: [
      { required: true, message: "省不能为空", trigger: "blur" }
    ],
    address: [
      { required: true, message: "详细地址不能为空", trigger: "blur" }
    ],
    recommend: [
      { required: true, message: "推荐不能为空", trigger: "change" }
    ],
    top: [
      { required: true, message: "置顶不能为空", trigger: "change" }
    ],
    status: [
      { required: true, message: "状态不能为空", trigger: "change" }
    ],
  }
})

const { queryParams, form, rules } = toRefs(data)

onMounted(() => {
  getList()
})

/** 查询金融机构信息列表 */
function getList() {
  loading.value = true
  listOrganization(queryParams.value).then(response => {
    organizationList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  checkOpen.value = false
  reset()
}
/*function handleTabChange(tabContext) {
  const tabValue = tabContext.paneName; // 获取当前 tab 的 name（即 audit 值）
  queryParams.value.audit = tabValue;   // 正确更新查询参数
  console.log(queryParams)
  getList();                            // 重新请求数据
}*/
function handleTabChange(tabName) {
  // tabName 是 string 类型，比如 '0', '1'
  queryParams.value.audit = tabName || '' // 防空
  queryParams.value.pageNum = 1 // 切换 tab 时重置分页
  console.log('当前 audit 筛选值:', queryParams.value.audit)
  getList()
}
// 表单重置
function reset() {
  form.value = {
    id: null,
    parentId: null,
    orgType: null,
    level: null,
    orgCode: null,
    orgPath: null,
    orgName: null,
    orgUrl: null,
    shortName: null,
    logo: null,
    recommendLogo: null,
    introduction: null,
    national: null,
    nationalCode: null,
    province: null,
    city: null,
    district: null,
    provinceCode: null,
    cityCode: null,
    districtCode: null,
    address: null,
    recommend: null,
    top: null,
    status: null,
    sort: null,
    productTotal: null,
    dockingTotal: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    deleted: "0",
    version: "0",
    remark: null,
    whitelistMarker: null,
    financingProcess: null,
    audit: null,
    auditDesc: null
  }
  bizOrganizationAuditList.value = []
  proxy.resetForm("organizationRef")
  proxy.resetForm("checkRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  // 手动重置 CityChoose 组件绑定的值
  queryParams.value.provinceSiteId = null
  queryParams.value.citySiteId = null
  queryParams.value.areaSiteId = null
  // 重置分页
  queryParams.value.pageNum = 1
  // 触发查询（会获取最新数据）
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd(row) {
  if(row.level === 7){
    proxy.$modal.msgError("当前机构层级不能添加分支")
    return // 中断执行
  }

  reset()
  const _id = row.id || ids.value;
  form.value.parentId = _id;
  form.value.parentOrgName = row.orgName;
  form.value.level = setOrganizationLevel(row.level);
  open.value = true
  title.value = "添加金融机构信息"
}

function setOrganizationLevel(level){
  if(level < 7){
    return level + 1;
  }
}

/** 审核按钮操作 */

function handleCheck(row) {
  reset()
  const _id = row.id || ids.value
  getOrganization(_id).then(response => {
    const data = response.data

    // 假设取 bizOrganizationAuditList 中的第一条记录（或根据状态筛选）
    const latestAudit = data.bizOrganizationAuditList && data.bizOrganizationAuditList.length > 0
      ? data.bizOrganizationAuditList[0]
      : {}

    // 将主表数据赋值给 form（不包含 audit 字段）
    form.value = {
      ...data, // 其他字段
      audit: latestAudit.audit || '',        // 从 audit list 中提取
      auditDesc: latestAudit.auditDesc || '' // 从 audit list 中提取
    }

    // 保留 audit list 用于表格展示或其他用途
    bizOrganizationAuditList.value = data.bizOrganizationAuditList

    checkOpen.value = true
    title.value = "审核金融机构信息"
  })
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getOrganization(_id).then(response => {
    form.value = response.data
    bizOrganizationAuditList.value = response.data.bizOrganizationAuditList
    open.value = true
    title.value = "修改金融机构信息"
  })
}

/** 提交审核 */
function submitCheckForm() {
  proxy.$refs["checkRef"].validate(valid => {
    if (valid) {
      form.value.bizOrganizationAuditList = bizOrganizationAuditList.value
      if (form.value.id != null) {
        check(form.value).then(response => {
          proxy.$modal.msgSuccess("审核成功")
          checkOpen.value = false
          getList()
        })
      }
    }
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["organizationRef"].validate(valid => {
    if (valid) {
      form.value.bizOrganizationAuditList = bizOrganizationAuditList.value
      if (form.value.id != null) {
        updateOrganization(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addOrganization(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除金融机构信息编号为"' + _ids + '"的数据项？').then(function () {
    return delOrganization(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {
  })
}

/** 金融机构审核序号 */
function rowBizOrganizationAuditIndex({ row, rowIndex }) {
  row.index = rowIndex + 1
}

/** 金融机构审核添加按钮操作 */
function handleAddBizOrganizationAudit() {
  let obj = {}
  obj.audit = ""
  obj.auditDesc = ""
  obj.auditTime = ""
  obj.deleted = ""
  obj.version = ""
  obj.remark = ""
  bizOrganizationAuditList.value.push(obj)
}

/** 金融机构审核删除按钮操作 */
function handleDeleteBizOrganizationAudit() {
  if (checkedBizOrganizationAudit.value.length == 0) {
    proxy.$modal.msgError("请先选择要删除的金融机构审核数据")
  } else {
    const bizOrganizationAudits = bizOrganizationAuditList.value
    const checkedBizOrganizationAudits = checkedBizOrganizationAudit.value
    bizOrganizationAuditList.value = bizOrganizationAudits.filter(function (item) {
      return checkedBizOrganizationAudits.indexOf(item.index) == -1
    })
  }
}

/** 复选框选中数据 */
function handleBizOrganizationAuditSelectionChange(selection) {
  checkedBizOrganizationAudit.value = selection.map(item => item.index)
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('manage/organization/export', {
    ...queryParams.value
  }, `organization_${new Date().getTime()}.xlsx`)
}

// 跳转到机构人员页面，携带机构ID（或其他参数）
function handleToUsers(row) {
  router.push({
    path: '/platform/finance/org/user/index',
    // query: { orgId: row.id } // 可选：传递当前机构ID
  });
}

getList()
</script>
